package band.wukong.practice.javase.core.io.file;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.regex.Pattern;

/**
 * Desc: 文件目录列表器 v1.0
 * Author: sunjs
 * Date: 2009-12-11 10:26:32
 */
public class DirList1 {

    public static void main(String[] args) {
        File path = new File("src\\com\\jsun\\javase\\corepackage\\io");
        System.out.println("path.getAbsolutePath() = " + path.getAbsolutePath());

        String[] list;
//        list = path.list();
        list = path.list(new DirFilter(".*.java"));

        Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
        for (String dirItem : list) {
            System.out.println("dirItem = " + dirItem);
        }
    }

    /**
     * Desc: directory filter
     * Author: sunjs
     * Date: 2009-12-11 10:27:37
     */
    public static class DirFilter implements FilenameFilter {
        private Pattern pattern;

        public DirFilter(String regex) {
            pattern = Pattern.compile(regex);
        }

        public boolean accept(File dir, String name) {
            return pattern.matcher(name).matches();
        }

    }
}
